const express = require('express');
const router = express.Router();
const roleController = require('../controllers/roleController');
const { requirePermission } = require('../middlewares/roleMiddleware.js');

/**
 * POST /api/roles
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 新增角色
 * @tags role
 * @param {object} role - 角色对象
 * @return {object} 200 - success
 */
router.post('/roles',requirePermission('role:create'), roleController.addRoleController);
/**
 * GET /api/roles
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 获取所有角色
 * @tags role
 * @return {object} 200 - success
 */
router.get('/roles', roleController.getAllRolesController);

/**
 * PUT /api/roles/{id}
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 更新角色
 * @tags role
 * @param {object} role - 角色对象
 * @param {string} id.path - 角色id
 * @return {object} 200 - success
 */

router.put('/roles/:id', requirePermission('role:update'), roleController.updateRoleController);

/**
 * DELETE /api/roles/{id}
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 删除角色
 * @tags role
 * @param {string} id.path - 角色id
 * @return {object} 200 - success
 */

router.delete('/roles/:id', requirePermission('role:delete'), roleController.deleteRoleController);

/**
 * GET /api/roles/{id}/permissions
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 获取角色权限
 * @tags role
 * @param {string} id.path - 角色id
 * @return {object} 200 - success
 */
router.get('/roles/:id/permissions', roleController.getRolePermissionsController);
/**
 * POST /api/roles/{id}/permissions
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 分配权限给角色
 * @tags role
 * @param {string} id.path - 角色id
 * @param {Array} request.body.required - 请求体参数
 * @return {object} 200 - success
 */
router.post('/roles/:id/permissions', requirePermission('permission:assign'), roleController.assignPermissionsController);

/**
 * GET /api/permissions
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 获取所有权限
 * @tags role
 * @return {object} 200 - success
 */
router.get('/permissions', roleController.getAllPermissionsController);

/**
 * GET /api/roles/{id}/menus
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 获取角色菜单
 * @tags role
 * @param {string} id.path - 角色id
 * @return {object} 200 - success
 */
router.get('/roles/:id/menus', roleController.getRoleMenusController);

/**
 * POST /api/roles/{id}/menus
 * @security BearerAuth
 * @header {string} Authorization - Bearer Token认证信息，格式为: Bearer {token}
 * @summary 分配菜单给角色
 * @tags role
 * @param {string} id.path - 角色id
 * @param {Array} request.body.required - 请求体参数
 * @return {object} 200 - success
 */

router.post('/roles/:id/menus', requirePermission('menu:assign'), roleController.assignMenusController)


module.exports = router;